# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=sqlninja
pkgver=0.2.999
pkgrel=11
groups=('blackarch' 'blackarch-exploitation' 'blackarch-fuzzer'
        'blackarch-webapp')
pkgdesc='A tool targeted to exploit SQL Injection vulnerabilities on a web application that uses Microsoft SQL Server as its back-end.'
arch=('any')
url='http://sqlninja.sourceforge.net/'
license=('GPL2')
depends=('perl' 'perl-netpacket' 'perl-net-pcap' 'perl-net-dns' 'perl-net-rawip'
         'perl-io-socket-ssl' 'perl-dbi' 'perl-dbd-sqlite')
optdepends=('metasploit: to use the metasploit attack mode'
            'tigervnc: a VNC client, vncviewer, to use the VNC payload')
conflicts=('sqlninja-svn')
source=("http://downloads.sourceforge.net/sourceforge/$pkgname/$pkgname-$pkgver-alpha1.tgz"
        'sqlninja.patch')
sha512sums=('86ec16202098f1e51049f8db6e8567486f2dfb4626c402b03cc9a5f2c43001b3c759cdaac4880886be002a53f44848bc1da896aeaa9194f5050676e24c2ecfa8'
            'f0fd216092e84836cf7153bce4cb7977de1f8ccb707ccd06785b1c009426886e436f690ba70b302542dadd192b256f0909a91f4b9c00740f7a47760e2f7cf84d')

prepare() {
  cd "$pkgname-$pkgver-alpha1"

  if [[ -d /usr/src/metasploit ]] ; then
    sed -i 's|/home/user/trunk/|/opt/metasploit|g' "$pkgname.conf"
  else
    sed -i 's|/home/user/trunk/|/opt/metasploit|g' "$pkgname.conf"
  fi

  patch -p0 < "$srcdir/$pkgname.patch"
}


package() {
  cd "$pkgname-$pkgver-alpha1"

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" ChangeLog README \
    sqlninja-howto.html
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm ChangeLog README sqlninja-howto.html

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/bash
cd /usr/share/$pkgname
exec perl ./$pkgname "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

